package com.csd.action.manager;

import java.util.Iterator;
import java.util.List;

import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import com.csd.helper.ActionResult;
import com.csd.helper.IConstant;
import com.csd.vo.UserVO;


/**
 * 为项目添加或删除评审老师
 * @author sanmu
 * 	<br> 创建于2009-12-29
 *
 */
public class EvaluationTeacherAddOrDeleteAction {
	private Integer teacherID;
	
	private String teacherName;
	
	private String addOrDel;

	public Integer getTeacherID() {
		return teacherID;
	}

	public void setTeacherID(Integer teacherID) {
		this.teacherID = teacherID;
	}

	public String getTeacherName() {
		return teacherName;
	}

	public void setTeacherName(String teacherName) {
		this.teacherName = teacherName;
	}

	public String getAddOrDel() {
		return addOrDel;
	}

	public void setAddOrDel(String addOrDel) {
		this.addOrDel = addOrDel;
	}
	
	public String execute()throws Exception{
		String text = ActionResult.fail;
		HttpSession httpSession = ServletActionContext.getRequest().getSession();
		List<UserVO> eList = (List<UserVO>)httpSession.getAttribute(IConstant.evaluationTeacherList);
		List<UserVO> sList = (List<UserVO>)httpSession.getAttribute(IConstant.selectTeacherList);
		if (eList != null || sList != null) {
			if (addOrDel.equals("add")) {
				for (Iterator iterator = sList.iterator(); iterator.hasNext();) {
					UserVO u = (UserVO) iterator.next();
					if (u.getUserID()==teacherID) {
						sList.remove(u);			//把添加的老师从可选老师中删除
					}
					eList.add(new UserVO(teacherID,"","",teacherName));  //添加到评审老师里面
				}
			}else if (addOrDel.equals("delete")) {
				for (Iterator iterator = eList.iterator(); iterator.hasNext();) {
					UserVO u = (UserVO) iterator.next();
					if (u.getUserID()==teacherID) {
						eList.remove(u);
					}
					sList.add(new UserVO(teacherID,"","",teacherName));
				}
			}
			httpSession.setAttribute(IConstant.evaluationTeacherList, eList);
			httpSession.setAttribute(IConstant.selectTeacherList, sList);
		}
		text = ActionResult.success;
		return text;
	}
}
